package fyp.spedmew;

import android.app.DialogFragment;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;


public class CreateJobInitStageActionBarActivity extends ActionBarActivity {

    Bundle jobData = new Bundle();
    private static final String TAG = new Object(){}.getClass().getCanonicalName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_job_init_stage);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_create__shipment, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public void setDate(View view) {
        DialogFragment f = new DatePickerDialogFragment();
        f.show(getFragmentManager(), "datePicker");
    }

    public void sendMessage(View view) {
        final Button btn = (Button) findViewById(R.id.nextInit);
        btn.setBackgroundColor(getResources().getColor(R.color.button_BG_OnPressed));

        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                btn.setBackgroundColor(getResources().getColor(R.color.button_BG));
            }
        }, 300);

        Intent out = new Intent(this, CreateJobAddPictureActionBarActivity.class);

        EditText nameET = (EditText) findViewById(R.id.item_name);
        EditText descrET = (EditText) findViewById(R.id.item_description);
        EditText dateET = (EditText) findViewById(R.id.item_date);
        EditText priceET = (EditText) findViewById(R.id.item_price);

        jobData.putString("name", nameET.getText().toString());
        jobData.putString("descr", descrET.getText().toString());
        jobData.putString("date", dateET.getText().toString());
        jobData.putString("price", priceET.getText().toString());

        out.putExtras(jobData);
        startActivity(out);
    }
}
